<!-- 发文（函）公文详情-->
<template>
  <view>
    <van-popup v-model="showCompo" closeable round position="bottom" :style="{ height: '100%' }"
               @click-close-icon="toClose" @click-overlay="toClose">
      <van-row type="flex" justify="center">
        <van-col offset="1" span="24">
          <van-cell style="text-align: center;">{{fwInfo.title}}</van-cell>
        </van-col>
      </van-row>
      <van-form>
        <van-collapse v-model="tableShow" accordion :border="border"
                      style="word-break: break-word !important;">
          <van-collapse-item icon="label-o" title="基本信息" title-class="text-bold" name="jbxx">
            <van-cell-group :border="border">
              <van-row class="content-border">
                <van-col span="8" class="content-title">发文字号</van-col>
                <van-col span="16" class="content-value">{{ basicInfo.FILE_SIZE }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">密级</van-col>
                <van-col span="16" class="content-value">
                  {{ this.dict.getDictNameByDictCode('mj', fwInfo.secrecyLevel) }}
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">紧急程度</van-col>
                <van-col span="16" class="content-value">
                  {{ this.dict.getDictNameByDictCode('jjcd',fwInfo.emergencyLevel) }}
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">主送</van-col>
                <van-col span="16" class="content-value">{{ fwInfo.mainTo }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">抄送</van-col>
                <van-col span="16" class="content-value">{{ fwInfo.copyTo }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">拟稿</van-col>
                <van-col span="16" class="content-value">{{ fwInfo.drafterDeptName }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">姓名</van-col>
                <van-col span="16" class="content-value">{{ fwInfo.drafterName }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">电话</van-col>
                <van-col span="16" class="content-value">{{ fwInfo.drafterPhone }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">是否公开</van-col>
                <van-col span="16" class="content-value">
                  {{ this.dict.getDictNameByDictCode('infopublic', fwInfo.infoDisclosure) }}
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">印制份数</van-col>
                <van-col span="16" class="content-value">{{ fwInfo.printFileNum }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">标题</van-col>
                <van-col span="16" class="content-value text-blue" @click="openFw">{{ fwInfo.title }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">正文</van-col>
                <van-col span="16" class="content-value">
                  <template v-if="detailDoc !=null">
                    <view v-for="item in detailDoc" @click="lx.openFile(item, proInstId)">
                      <span style="color: #0081ff;">{{ item.attachName }}</span>
                    </view>
                  </template>
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">附件</van-col>
                <van-col span="16" class="content-value">
                  <template v-if="detailAttachment != undefined && detailAttachment.length > 0 ">
                    <view v-for="item in detailAttachment"  @click="lx.openFile(item, proInstId)">
                      <span style="color: #0081ff;">{{ item.attachName }}</span>
                    </view>
                  </template>
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">签发意见</van-col>
                <van-col span="16" class="content-value">
                  <template v-if="opinion != null && opinion != undefined">
                    <view class="opinion" v-for="item in opinion">
                      <view class="opinion-left">{{ item.parentDeptName }}</view>
                      <view class="opinion-left">{{ item.opinion }}</view>
                      <view class="opinion-right">
                        <!-- base64签名图片 -->
                        <img v-if="item.signature != '' && item.signature != undefined"
                             :src="`data:image/png;base64,`+item.signature" alt="图片未上传"/>
                        <text v-else class="opinion-user">{{ item.userName }}</text>
                        <text class="opinion-date">{{ item.approvalTime }}</text>
                      </view>
                    </view>
                  </template>
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">提交部门</van-col>
                <van-col span="16" class="content-value">{{ submitDeptName }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">提交人</van-col>
                <van-col span="16" class="content-value">{{ basicInfo.USER_NAME }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">提交时间</van-col>
                <van-col span="16" class="content-value">{{ basicInfo.SUBMISSION_TIME }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">联系电话</van-col>
                <van-col span="16" class="content-value">{{ basicInfo.CONTACT_NUMBER }}</van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">收发方式</van-col>
                <van-col span="16" class="content-value">
                  {{
                    basicInfo.SENDING_RECEIVING == 1 ? "司局自发" : basicInfo.SENDING_RECEIVING == 2 ? "收发室代发" : ""
                  }}
                </van-col>
              </van-row>
              <van-row class="content-border">
                <van-col span="8" class="content-title">备注</van-col>
                <van-col span="16" class="content-value">{{ basicInfo.REMARKS }}</van-col>
              </van-row>
            </van-cell-group>
          </van-collapse-item>
          <van-collapse-item icon="font-o" title="排版信息" title-class="text-bold" name="pb">
            <van-cell-group :border="border">
              <van-row class="content-border">
                <van-col span="8" class="content-title">排版人</van-col>
                <van-col span="8" class="content-title">排版时间</van-col>
                <van-col span="8" class="content-title">排版文件</van-col>
              </van-row>
              <van-row class="content-border" v-for="item in pbInfo">
                <van-col span="8" class="content-value" style="text-align: left;">{{ item.userName }}</van-col>
                <van-col span="8" class="content-value" style="text-align: left;">{{ dateFormat(item.createTime) }}</van-col>
                <van-col span="8" class="content-value text-blue" style="text-align: left;" onclick="lx.openFile(item,proInstId)">
                  {{ item.attachName }}
                </van-col>
              </van-row>
            </van-cell-group>
          </van-collapse-item>
        </van-collapse>
      </van-form>
    </van-popup>
  </view>
</template>

<script>
export default {
  props: {
    showDetail: {
      type: Boolean,
      default: false
    },
  },
  watch: {
    showDetail(val){
      this.showCompo = val;
    }
  },
  data() {
    return {
      showCompo: false,
      border: false,
      tableShow: "jbxx",
      proInstId: '',
      basicInfo: {}, // 基本信息
      fwInfo: {},    // 发文信息
      pbInfo: [],    // 排版信息
      opinion: [],   // 意见
      detailDoc: [], // 正文
      detailAttachment: [], // 附件
      submitDeptName: '',   // 提交部门
      mj: [],   // 密级
      hj: [],   // 缓急
      sfgk: [], // 是否公开
    };
  },
  mounted() {
    // 加载字典
    this.getDict();
  },
  methods: {
    init(fwId) {
      this.proInstId = fwId;
      this.getListData(fwId);
      this.getFwDetail(fwId);
    },
    // 获取基本信息
    getListData(id) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fwend/getListData`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'FW_ID': id,
          'page': 1,
          'rows': 1,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.basicInfo = data.data.rows[0];
          this.getDeptInfo(data.data.rows[0].SUBMITTING_DEPARTMENT);
        }
      });
    },

    // 发文信息
    getFwDetail(id) {
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/` + id),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,//固定值
          'systemFlag': this.cache.get('userInfo').systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("获取公文要素详情data: " + JSON.stringify(data));
        if (data.code == 200) {
          this.fwInfo = data.data;
          this.getPbInfo(data.data.extendIdForRelate);
          this.getCaacOpinion(data.data.proInstId);
          this.getCaacBody(data.data.extendIdForRelate);
          this.getCaacAttachment(data.data.extendIdForRelate);
        }
      })
    },

    // 排版信息
    getPbInfo(id) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/oabizattachment/findByBizIdOrdrtBy/` + id),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.pbInfo = data.data;
        }
      });
    },

    // 获取意见
    getCaacOpinion(proInstId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/approvalwrite`),
        method: 'get',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (data.data != null) {
            this.opinion = data.data.jldReview;
          }
        }
        console.log("------意见-approvalwrite: " + JSON.stringify(data));
      })
    },

    // 获取正文数据
    getCaacBody(relateId) {
      const _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/maintext/proInstId/` + relateId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          console.log("------正文-detailDoc: " + JSON.stringify(data.data));
          _this.detailDoc = data.data.doc
        }
      })
    },

    // 获取附件数据
    getCaacAttachment(relateId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderByNew`),
        method: 'get',
        params: this.$http.adornParams({
          'bizId': relateId,
          'attachTypeId': 'pageBody_uploadFile',
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailAttachment = data.data
        }
        console.log("------附件-attachmentinfoOrderBy: " + JSON.stringify(_this.detailAttachment));
      })
    },

    // 获取部门信息
    getDeptInfo(deptId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/comm/comm/findAllParentDeptByDeptId`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'deptId': deptId,
        })
      }).then(({data}) => {
        if (data.code == 200) {
          for (let i = 0; i < data.data.length; i++) {
            if (data.data[i].deptLevel == 2) {
              this.submitDeptName = data.data[i].deptName + data.data[i - 1].deptName;
              break;
            }
          }
        }
      });
    },

    // 打开发文页面
    openFw() {
      uni.navigateTo({
        url:"/pages/caac/send/index?proInstId="+ this.fwInfo.proInstId
      })
    },

    // 取消按钮
    toClose() {
      this.$emit('closeDetail', this.showCompo);
    },

    // 获取需要的字典项
    getDict() {
      const dictSecrecyLevel = this.cache.get('mj')//密级
      this.mj = []
      dictSecrecyLevel.forEach((item) => {
        this.mj.push({name: item.dictItemName, dictItemCode: item.dictItemCode})
      })

      const dictEmergencyLevel = this.cache.get('jjcd')//紧急程度
      this.hj = []
      dictEmergencyLevel.forEach((item) => {
        this.hj.push({name: item.dictItemName, dictItemCode: item.dictItemCode})
      })


      const dictInfoDisclosure = this.cache.get('infopublic')//是否公开
      this.sfgk = []
      dictInfoDisclosure.forEach((item) => {
        this.sfgk.push({name: item.dictItemName, dictItemCode: item.dictItemCode})
      })

    },

    // 时间格式化
    dateFormat(dateTime) {
      let formatStr = dateTime
      if (dateTime != null && dateTime != '' && dateTime.length > 10) {
        formatStr = dateTime.substr(0, 10)
      }
      return formatStr
    },
  },
};
</script>

<style scoped>
/* 意见相关样式 */
.opinion{
  display: flex;
  flex-direction: column;
  margin: 0 32rpx;
  padding: 20rpx 0rpx;
  overflow: hidden;
  font-size: 28rpx;
  line-height: 24px;
  border-bottom: 1px solid #ebedf0;

}
.opinion .opinion-left{
  text-align: left;
  color: #323233;
}
.opinion .opinion-right{
  text-align: right;
  color: #969799;
}

.van-cell__title {
  min-width: 55%;

  span {
    display: inline-block;
    text-align: left;
    word-break: break-all;
  }
}

.van-cell__value--alone {
  color: #323233;
  text-align: center;
}

/deep/ .van-collapse-item__content {
  padding: 0px;
  color: #969799;
  font-size: 14px;
  line-height: 1.5;
  background-color: #fff;
}

/deep/ .van-field__label {
  color: #323233;
  min-width: 50%;

span {
  display: inline-block;
  text-align: left;
  word-break: break-all;
}
}

/deep/ .van-field__control {
  font-size: 14px;
  color: #969799;
}
/deep/ .content-border {
  border-bottom: 1rpx solid #e4e4e4;
  display: flex;
}
.content-title {
  background-color: #f2f2f2;
  padding: 10px 15px;
  color: #646566;
}
.content-value {
  padding: 10px 15px;
  text-align: right;
}
.content-red {
  color: #ed1c24;
}
.content-blue {
  color: #0081ff;
}
</style>
